const Service = require('egg').Service

class RegService extends Service {

  async postReg(body) {
    let resUser = await this.app.model.User.findOne({
      where:{
        username:body.username
      }
    })
    let resAdimn = await this.app.model.Admin.findOne({
      where:{
        adminname:body.username
      }
    })
    if(resUser || resAdimn) {
      return {code:40000}
    }else {
      let username = body.username
      let password = body.password
      let auth = 0
      return await this.app.model.User.create({
        username:username,
        password:password,
        auth:0,
        status:0,
        headImg:'https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1338/baseimg.jpeg',
        selfIntroduction:'hello~'
      })
    }
  }

}

module.exports = RegService